import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/Login.vue'
import LayOut from '../views/LayOut/LayOut.vue'
// meta数组内权限配置:'0':超级管理员，'1':系统管理员，'2':老师，'3':学生，'4':辅导员
const routes = [
  {
    path: '/',
    redirect: '/login',
    isShow:false
  },
  {
    path: '',
    redirect: '/login',
    isShow:false
  },
  {
    path: '/login',
    component: Login,
    isShow:false
  },
  /**==================================== */
  // 首页
  {
    path: '',
    component: LayOut,
    isShow: true,
    meta:['0','1','2','3','4'],
    icon:"icon-home",
    children: [
      {
        path: '/home',
        name: '主页',
        isShow: true,
        meta:['0','1','2','3','4'],
        component: () => import("../views/LayOut/Home/home.vue")
      },
    ]
  },
  // 考勤管理
  {
    path: '',
    component: LayOut,
    isShow: true,
    meta: ['0','3','4'],
    icon:"icon-job",
    children: [
      {
        path: '/attendanceManagement',
        name: '考勤管理',
        isShow: true,
        meta: ['0','3','4'],
        component: () => import("../views/LayOut/AttendanceManagement/attendanceManagement.vue")
      }
    ]
  },
  // 用户管理
  {
    path: '',
    component: LayOut,
    isShow: true,
    meta: ['0','1'],
    icon:"icon-yonghu",
    children: [
      {
        path: '/userManagement',
        name: '用户管理',
        isShow: true,
        meta: ['0','1'],
        component: () => import("../views/LayOut/UserManagement/userManagement.vue")
      }
    ]
  },
  // 成绩管理
  {
    path: '',
    component: LayOut,
    isShow: true,
    meta: ['0','2','3','4'],
    icon:"icon-areachart",
    children: [
      {
        path: '/achievementManagement',
        name: '成绩管理',
        isShow: true,
        meta: ['0','2','3','4'],
        component: () => import("../views/LayOut/AchievementManagement/achievementManagement.vue")
      }
    ]
  },
  // 学生消费管理
  {
    path: '',
    component: LayOut,
    isShow: true,
    meta: ['0','1','3'],
    icon:"icon-xiaofei",
    children: [
      {
        path: '/consumptionManagement',
        name: '学生消费管理',
        isShow: true,
        meta: ['0','1','3'],
        component: () => import("../views/LayOut/ConsumptionManagement/consumptionManagement.vue")
      }
    ]
  },
  // 辅导员学生
  {
    path: '',
    component: LayOut,
    isShow: true,
    meta: ['0','4'],
    icon:"icon-huabi",
    children: [
      {
        path: '/students',
        name: '辅导员学生',
        isShow: true,
        meta: ['0','4'],
        component: () => import("../views/LayOut/Students/students.vue")
      }
    ]
  },
  // 异常学生
  {
    path: '',
    component: LayOut,
    isShow: true,
    meta: ['0','4'],
    icon:"icon-huabi",
    children: [
      {
        path: '/abnormalStudent',
        name: '异常学生',
        isShow: true,
        meta: ['0','4'],
        component: () => import("../views/LayOut/AbnormalStudent/abnormalStudent.vue")
      }
    ]
  },
  // 系统维护
  {
    path: '/Set',
    component: LayOut,
    isShow: true,
    name:"系统维护",
    meta: ['0','1'],
    icon:"icon-yonghu",
    children: [
      {
        path: 'subject',
        name: '学科',
        isShow: true,
        meta: ['0','1'],
        component: () => import("../views/LayOut/Set/subject.vue")
      },
      {
        path: 'class',
        name: '班级',
        isShow: true,
        meta: ['0','1'],
        component: () => import("../views/LayOut/Set/class.vue")
      },
      {
        path: 'role',
        name: '角色',
        isShow: true,
        meta: ['0','1'],
        component: () => import("../views/LayOut/Set/role.vue")
      },
      {
        path: 'semester',
        name: '学期',
        isShow: true,
        meta: ['0','1'],
        component: () => import("../views/LayOut/Set/semester.vue")
      },
      {
        path: 'attendance',
        name: '考勤类型',
        isShow: true,
        meta:['0','1'],
        component: () => import("../views/LayOut/Set/attendance.vue")
      },
      {
        path: 'examination',
        name: '考试类型',
        isShow: true,
        meta: ['0','1'],
        component: () => import("../views/LayOut/Set/examination.vue")
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  let token = sessionStorage.getItem("token");
  if (to.path == "/login") {
    next()
  } else if (token) {
    next()
  } else {
    router.push("/login")
  }
});
export default router
